import { createStore } from "vuex";

// 创建 store
const store = createStore({
  // 开启严格模式
  strict: true,

  /**
   * 仓库中的数据
   */
  state() {
    return {
      msg: "~",
      count: 1,
    };
  },

  getters: {},

  /**
   * 声明 mutation
   */
  mutations: {
    /**
     * state - 当前 state 数据
     * payload - commit 这个 mutation 时，传递过来的参数
     */
    changeMsg(state, payload) {
      console.log("payload", payload);
      if (payload.name) {
        state.msg = payload.name;
      } else {
        state.msg += "~";
      }
    },
  },

  actions: {},

  modules: {},
});

export default store;
